package javaer.starter.idea.util;

import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.MavenProject;

import java.io.File;
import java.io.FileReader;

/**
 * @author yangzhen
 * @date 2023/7/4 18:18
 * @since 1.0.0
 */
public class MavenApacheUtils {

    public static MavenProject getMavenProject(String pomPath) {
        try {
            File pomFile = new File(pomPath);

            MavenXpp3Reader reader = new MavenXpp3Reader();
            Model model;

            try (FileReader fileReader = new FileReader(pomFile)) {
                model = reader.read(fileReader);
            }
            MavenProject project = new MavenProject(model);
            return project;
        } catch (Exception e) {
            throw new RuntimeException();
        }
    }
}
